001 /*
002 * Copyright 2005 Stephen J. McConnell
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
013 * implied.
014 *
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package net.dpml.library.info;
020
021 import java.util.Properties;
022
023 import net.dpml.lang.Enum;
024
025 /**
026 * The ImportDirective class describes a the import of resource via a file or uri reference.
027 *
028 * @author <a href="http://www.dpml.net">The Digital Product Meta Library</a>
029 * @version 1.0.0
030 */
031 public final class ImportDirective extends AbstractDirective
032 {
033 /**
034 * URI strategy constant.
035 */
036 public static final Mode URI = Mode.URI;
037
038 /**
039 * File strategy constant.
040 */
041 public static final Mode FILE = Mode.FILE;
042
043 private Mode m_mode;
044 private final String m_value;
045
046 /**
047 * Creation of a new import directive.
048 * @param mode the import mode
049 * @param value the value (file or uri depending on mode)
050 */
051 public ImportDirective( Mode mode, String value )
052 {
053 this( mode, value, null );
054 }
055
056 /**
057 * Creation of a new import directive.
058 * @param mode the import mode
059 * @param value the value (file or uri depending on mode)
060 * @param properties supplimentary properties
061 */
062 public ImportDirective( Mode mode, String value, Properties properties )
063 {
064 super( properties );
065
066 if( null == mode )
067 {
068 throw new NullPointerException( "mode" );
069 }
070 if( null == value )
071 {
072 throw new NullPointerException( "value" );
073 }
074
075 m_mode = mode;
076 m_value = value;
077 }
078
079 /**
080 * Return the import mode.
081 * @return the mode
082 */
083 public Mode getMode()
084 {
085 return m_mode;
086 }
087
088 /**
089 * Return the import value.
090 * @return the value
091 */
092 public String getValue()
093 {
094 return m_value;
095 }
096
097 /**
098 * Compare this object with another for equality.
099 * @param other the other object
100 * @return true if equal
101 */
102 public boolean equals( Object other )
103 {
104 if( super.equals( other ) && ( other instanceof ImportDirective ) )
105 {
106 ImportDirective object = (ImportDirective) other;
107 if( !equals( m_mode, object.m_mode ) )
108 {
109 return false;
110 }
111 else
112 {
113 return equals( m_value, object.m_value );
114 }
115 }
116 else
117 {
118 return false;
119 }
120 }
121
122 /**
123 * Compute the hash value.
124 * @return the hashcode value
125 */
126 public int hashCode()
127 {
128 int hash = super.hashCode();
129 hash ^= super.hashValue( m_mode );
130 hash ^= super.hashValue( m_value );
131 return hash;
132 }
133
134 /**
135 * Mode of inclusion.
136 */
137 public static final class Mode extends Enum
138 {
139 static final long serialVersionUID = 1L;
140
141 /**
142 * File include stratgy constant.
143 */
144 public static final Mode FILE = new Mode( "file" );
145
146 /**
147 * URI include stratgy constant.
148 */
149 public static final Mode URI = new Mode( "uri" );
150
151 /**
152 * Internal constructor.
153 * @param label the enumeration label.
154 */
155 private Mode( String label )
156 {
157 super( label );
158 }
159
160 /**
161 * Create a now mode using a supplied mode name.
162 * @param value the mode name
163 * @return the mode
164 */
165 public static Mode parse( String value )
166 {
167 if( value.equalsIgnoreCase( "file" ) )
168 {
169 return FILE;
170 }
171 else if( value.equalsIgnoreCase( "uri" ) )
172 {
173 return URI;
174 }
175 else
176 {
177 final String error =
178 "Unrecognized module mode argument [" + value + "]";
179 throw new IllegalArgumentException( error );
180 }
181 }
182 }
183 }